
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="modal" id="approveWorkflowDiv" tabindex="-1" role="dialog" aria-hidden="true">

	<div class="modal-dialog" role="document">

		<div class="modal-content animated bounceInRight">

			<div class="modal-header">
				<h4 class="modal-title">单据审核</h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			</div>

			<div class="modal-body" style="padding-bottom: 20px;">
				<%-- 导入提示信息框 --%>
			    <c:if test="${hint!=null&&hint!=''}">
			   		<jsp:include page="../../common/alert/alert.jsp">
			   			<jsp:param value="${hint}" name="alertType"/>
			   			<jsp:param value="${alertMessage}" name="alertMessage"/>
			   		</jsp:include>
			    </c:if>
			
				<form id="cform">
					<div id="approveResultDiv" class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>审批结果</label>
						<div class="col-sm-9">
							<div class="i-checks" style="margin-top: 5px;">
	                        	<label><input type="radio" value="PASS" name="approveResult"><i></i> 同意</label>
	                        	<label style="margin-left: 60px;"><input type="radio" value="NOPASS" name="approveResult"><i></i> 拒绝</label>
                            </div>
						</div>
						<div class="hr-line-dashed"></div>
					</div>
					
					
					<div id="approveCommentDiv" class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>审批意见</label>
						<div class="col-sm-9">
							<textarea id="approveComment" name="approveComment" class="form-control" rows="5"></textarea>
						</div>
						<div class="hr-line-dashed"></div>
					</div>
					
					
					<div class="form-group row">
						<label class="col-sm-3 col-form-label"><span class="text-danger">*</span>下一审批人</label>
						<div class="col-sm-9">
							<select class="chosen-select form-control" name="approvePerson" id="approvePerson">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<c:forEach items="${requestScope.approvePersonMap}" var="approvePersonTemp">
	                        		<option value="${approvePersonTemp.key}">${approvePersonTemp.value}</option>
	                        	</c:forEach>
	                        </select>
	                        <span class="help-block m-b-none" style="color: silver;">选择单据流转的下一个审批人</span>
						</div>
						<div class="hr-line-dashed"></div>
					</div>
					

					<div class="form-group row m-b-none">
						<div class="col-sm-12 col-sm-offset-2 text-right">
							<button class="btn btn-white btn-lg" type="button"
								data-dismiss="modal">返回</button>
							&nbsp;
							<button
								class="ladda-button ladda-button-demo btn btn-primary btn-lg"
								data-style="expand-right">
								&nbsp;&nbsp;流转&nbsp;&nbsp;<i class="fa fa-check-square-o"></i>
							</button>
						</div>
					</div>
					
					<input type="hidden" id="billType" name="billType" value="${param.billType}"> 
					<input type="hidden" id="billHeadCode" name="billHeadCode" value="${param.billHeadCode}"> 
					<input type="hidden" id="confHeadCode" name="confHeadCode" value="${requestScope.confHeadCode}"> 
					<input type="hidden" id="confLineCode" name="confLineCode" value="${requestScope.confLineCode}">
					<input type="hidden" id="submitFlag" name="submitFlag" value="${param.submitFlag}"> 
					<input type="hidden" id="approveFlag" name="approveFlag" value="${param.approveFlag}"> 
				</form>
			</div>

		</div>

	</div>

</div>

<c:if test="${param.submitFlag=='Y'}">
	<script>
	$(document).ready(function(){
		$("#approveResultDiv").hide();
		$("#approveCommentDiv").hide();
	});
	</script>
</c:if>


<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
	$(document).ready(function() {
		//初始化chosen-select
		$('.chosen-select').chosen({width: "100%"});
		
		//初始化radio值
		if("${param.submitFlag}"!="Y"){
	        if("${param.approveFlag}"=="Y"){
				$("input[name='approveResult']").each(function(){
					if($(this).val()=="PASS"){
						$(this).prop("checked", true);
					}else{
						$(this).prop("checked", false);
						$(this).prop("disabled", true);
					}
				});
			}else{
				$("input[name='approveResult']").each(function(){
					if($(this).val()=="NOPASS"){
						$(this).prop("checked", true);
					}else{
						$(this).prop("checked", false);
						$(this).prop("disabled", true);
					}
				});
			}
		}
		
		//初始化radio
		$('.i-checks').iCheck({
            //checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        
        
		
		//表单提交
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#cform").valid();
			//l.ladda('stop');
		});

		$("#cform").validate({
			rules : {
				<c:if test="${param.submitFlag!='Y'}">
				approveResult : {
					required : true,
				},
				approveComment : {
					required : true,
				},
				</c:if>
				approvePerson : {
					required : true,
				}
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				if(submitFlag=="Y"){
					l.ladda('start');
					editLine();
				}
		    }
		});
		
	});
	
	//异步编辑行
	function editLine(){
		redragonJS.loading("tabDiv");
		
		$.ajax({
			type: "post",
			url: "web/cuxWorkflowRecord/editCuxWorkflowRecord",
			data: {"approveResult": redragonJS.getRadioValue("approveResult"), "approveComment": $("#approveComment").val(), "approvePerson": $("#approvePerson").val(),
				   "submitFlag": $("#submitFlag").val(), "approveFlag": $("#approveFlag").val(),
				   "billType": $("#billType").val(), "billHeadCode": $("#billHeadCode").val(), 
				   "confHeadCode": $("#confHeadCode").val(), "confLineCode": $("#confLineCode").val()},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				redragonJS.removeLoading("tabDiv");
				$('#approveWorkflowDiv').modal('hide');
				$('.ladda-button-demo').ladda('stop');
				
				var json = JSON.parse(data);
				if(json.result=="success"){
					if(json.callback=="submit"){
						submitData();
					}else if(json.callback=="reject"){
						rejectData();
					}else if(json.callback=="approved"){
						approveData("N");
					}else{
						window.location.reload();
						//alert(json.callback);
					}
				}else{
					redragonJS.alert("工作流流转错误");
				}
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}

</script>
